import {getArticleById} from "@/api/article";

export default {
    namespaced: true,
    state: {
        dialogFormVisible: false,
        dialogTitle: '',
        pageSize: 10,
        currentPage: 1,
        total: 0,
        // 修改添加的表单数据
        articleForm: {
            id: null,
            title: "" ,
            coverImg: "" ,
            articleContent: null ,
            remark: "" ,
            viewNum: null ,
        },
        // 表格数据
        tableData: [],
        // 表格选中数据
        multipleSelection: [],
    },
    getters: {},
    mutations: {
        openDialogForm(state, value) {
            state.dialogFormVisible = value.dialogFormVisible;
            state.dialogTitle = value.dialogTitle;
        },
        EditArticle(state, value) {
            state.dialogFormVisible = value.dialogFormVisible;
            state.dialogTitle = value.dialogTitle;
            Object.keys(state.articleForm).forEach((key) => {
                state.articleForm[key] = value.articleForm[key]
            })
        }
    },
    actions: {
        editArticle(state, id) {
            getArticleById(id).then((res) => {
                var params = {
                    dialogFormVisible: true,
                    dialogTitle: "修改文章",
                    articleForm: res.data.data
                }
                state.commit("EditArticle", params);
            })
        }
    },
}
